package com.lmx.javasendmail;

import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;

import lombok.Data;


@Data
public class MailInfo {

    /** 身份验证 */
    private boolean validate = false;

    /** 调试模式（可以看到程序发送Email的状态） */
    private boolean debugMode = false;

    /** 发送邮件的服务器IP */
    private String mailServerHost;

    /** 发送邮件的服务器端口 */
    private String mailServerPort;

    /** 登陆邮件发送服务的用户名 */
    private String account;

    /** 登陆邮件发送服务器的密码 */
    private String password;

    public Properties getProperties() {
        Properties properties = new Properties();
        properties.setProperty("mail.transport.protocol", "smtp");
        properties.setProperty("mail.store.protocol", "pop3");
        properties.put("mail.host", mailServerHost);
        properties.put("mail.port", mailServerPort);
        properties.put("mail.smtp.auth", validate);
        return properties;
    }

    public Authenticator getAuthenticator() {
        Authenticator authenticator = null;
        if (isValidate()) {
            authenticator = new Authenticator() {
                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(account, password);
                }
            };
        }
        return authenticator;
    }

}
